package com.iamalive;

import java.util.List;

import com.iamalive.LocalCache.InfoDetails;

import android.os.Bundle;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.widget.AdapterView;
import android.view.View;
import android.widget.ArrayAdapter;


public class InfoListActivity extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_info_list);
		//final ListView listview = (ListView) findViewById(R.id.listviewInfoList);
		
//		String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
//		        "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
//		        "Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux",
//		        "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2",
//		        "Android", "iPhone", "WindowsMobile" };
//
//		final ArrayList<String> list = new ArrayList<String>();
//		for (int i = 0; i < values.length; ++i) {
//			list.add(values[i]);
//		}

		final StableArrayAdapter adapter = new StableArrayAdapter(this,
				android.R.layout.simple_list_item_1, LocalCache.getSingleInstance().mInfoList);
		setListAdapter(adapter);

		getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, final View view,
					int position, long id) {
			   	//Toast.makeText(getApplicationContext(), "Click ListItem Number " + position, Toast.LENGTH_LONG).show();
				Intent i = new Intent(getApplicationContext(), UpdateInfoActivity.class);
				i.putExtra("Array Index", position);
				
			    startActivity(i);
			}
		});
	}

	private class StableArrayAdapter extends ArrayAdapter<InfoDetails> {

	    //HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

	    public StableArrayAdapter(Context context, int textViewResourceId,
	        List<InfoDetails> objects) {
	      super(context, textViewResourceId, objects);	      
	    }

/*	    @Override
	    public long getItemId(int position) {
	      InfoDetails infoDetails = getItem(position);
	      return mIdMap.get(item);
	    }

	    @Override
	    public boolean hasStableIds() {
	      return true;
	    }*/

	  }
	
//	private class StableArrayAdapter extends ArrayAdapter<String> {
//
//	    HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
//
//	    public StableArrayAdapter(Context context, int textViewResourceId,
//	        List<String> objects) {
//	      super(context, textViewResourceId, objects);
//	      for (int i = 0; i < objects.size(); ++i) {
//	        mIdMap.put(objects.get(i), i);
//	      }
//	    }
//
//	    @Override
//	    public long getItemId(int position) {
//	      String item = getItem(position);
//	      return mIdMap.get(item);
//	    }
//
//	    @Override
//	    public boolean hasStableIds() {
//	      return true;
//	    }
//
//	  }
	
	@Override
    protected void onResume() {
        super.onResume();

        //loginListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, populateList());
        //loginList.setAdapter(loginListAdapter);  
        
		final StableArrayAdapter adapter = new StableArrayAdapter(this,
				android.R.layout.simple_list_item_1, LocalCache.getSingleInstance().mInfoList);
		setListAdapter(adapter);
    }

}
